package main

import "fmt"

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

//4ms 30%, 2.5MB 43%
func levelOrder(root *TreeNode) []int {
	if root == nil {
		return nil
	}
	res, queue := []int{}, []*TreeNode{root}
	for i := 0; i < len(queue); i++ {
		res = append(res, queue[i].Val)
		if queue[i].Left != nil {
			queue = append(queue, queue[i].Left)
		}
		if queue[i].Right != nil {
			queue = append(queue, queue[i].Right)
		}
	}
	return res
}

func main() {
	fmt.Println(levelOrder(&TreeNode{}))
}
